
DEFINE VARIABLE hDoc AS HANDLE.
DEFINE VARIABLE hRoot AS HANDLE.
DEFINE VARIABLE hTable AS HANDLE.
DEFINE VARIABLE hField AS HANDLE.
DEFINE VARIABLE hLine AS HANDLE.
DEFINE VARIABLE hText AS HANDLE.

DEFINE VARIABLE i AS INTEGER.
DEFINE VARIABLE j AS INTEGER.
DEFINE VARIABLE k AS INTEGER.

CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.
CREATE X-NODEREF hTable.
CREATE X-NODEREF hField.
CREATE X-NODEREF hLine.
CREATE X-NODEREF hText.

FORM
    ad_addr  
    ad_name  FORMAT "x(30)"
    ad_attn  FORMAT "x(12)"
    ad_line1 FORMAT "x(60)" 
    WITH FRAME cust WIDTH 120 STREAM-IO DOWN .

/*read in the file created in the last example*/
hDoc:LOAD("file", "f:\hk_src\xml\cust.xml", FALSE).

hDoc:GET-DOCUMENT-ELEMENT(hRoot).

REPEAT i = 1 TO hDoc:NUM-CHILDREN WITH FRAME cust :

    hDoc:GET-CHILD(hTable,i).

    IF hTable:NUM-CHILDREN < 1 THEN NEXT.

    REPEAT j = 1 TO hTable:NUM-CHILDREN:

        hTable:GET-CHILD(hField,j).

        IF hField:NUM-CHILDREN < 1 THEN NEXT.

        DISP 
            hField:GET-ATTRIBUTE("CustNo") @ ad_addr 
            hField:GET-ATTRIBUTE("CustName") @ ad_name 
            WITH FRAME cust STREAM-IO .

        REPEAT k = 1 TO hField:NUM-CHILDREN:

            hField:GET-CHILD(hLine,k).

            IF hLine:NUM-CHILDREN < 1 THEN NEXT.

            hLine:GET-CHILD(hText,1).
        
            IF hLine:NAME = "Address" THEN
                DISP
                    hTEXT:NODE-VALUE @ ad_line1
                    WITH FRAME cust STREAM-IO .
            ELSE IF hLine:NAME = "ContactMan" THEN
                DISP
                    hTEXT:NODE-VALUE @ ad_attn
                    WITH FRAME cust STREAM-IO .

        END.

        DOWN 1 WITH FRAME cust STREAM-IO .

    END.

END.

PAUSE.
